package com.situ.b2c.address.controller;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.situ.b2c.address.service.AddrService;
import com.situ.b2c.pojo.Address;


@WebServlet("/AddressAddServlet")
public class AddressAddServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
   
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		
		String userName = request.getParameter("userName");
		String userPhone = request.getParameter("userPhone");
		String provinceCode = request.getParameter("provinceCode");
		System.out.println(Integer.parseInt(provinceCode));
		String cityCode = request.getParameter("cityCode");
		String districtCode = request.getParameter("districtCode");
		String addrName = request.getParameter("addrName");
	
		
		
		Address address = new Address();
		address.setUserName(userName);
		address.setUserPhone(userPhone);
		address.setProvinceCode(Integer.parseInt(provinceCode));
		address.setCityCode(Integer.parseInt(cityCode));
		address.setDistrictCode(Integer.parseInt(districtCode));
		address.setAddrName(addrName);
		
		
		
		AddrService addrService = new AddrService();
		addrService.insert(address, request);
		
		response.sendRedirect("address_daohang.jsp");
	}

	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		doGet(request, response);
	}

}
